
package util;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;


public class JpaUtil {

    private static EntityManagerFactory emf = null;

    public static EntityManager getEntityManager() {
        if (emf == null) {
            emf = Persistence.createEntityManagerFactory("sistemaagendamentoPU");
        }
        return emf.createEntityManager();
    }

    public static void closeEntityManager(EntityManager em) {
        try {
            em.close();
        } catch (Exception ex) {
            Logger.getLogger("Logger").log(Level.WARNING, "Problema na hora de fechar um Entitymanager: {0}", ex.getMessage());
        }
    }
}
